﻿package mortal.game.view.mainUI.smallMap.view.render
{
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.component.gconst.*;
    import mortal.game.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.view.common.*;
    import mortal.game.view.mainUI.smallMap.view.data.*;

    public class SmallMapCustomXYFixer extends GCellRenderer
    {
        private var _index:int;
        private var _line:ScaleBitmap;
        private var _txtName:GTextInput;
        private var _txtMapName:GTextInput;
        private var _lX:GLabel;
        private var _txtX:GTextInput;
        private var _lY:GLabel;
        private var _txtY:GTextInput;
        private var _btnCur:GLoadedButton;
        private var _myData:SmallMapCustomXYData;

        public function SmallMapCustomXYFixer(param1:int)
        {
            this._index = param1;
            return;
        }// end function

        override public function set label(param1:String) : void
        {
            return;
        }// end function

        public function getChangeData() : SCustomPoint
        {
            var _loc_1:* = int(this._txtX.text);
            var _loc_2:* = int(this._txtY.text);
            if (_loc_1 <= 0 && _loc_2 <= 0)
            {
                return null;
            }
            var _loc_3:* = new SCustomPoint();
            _loc_3.point = new SPoint();
            _loc_3.point.x = _loc_1;
            _loc_3.point.y = _loc_2;
            _loc_3.index = this._index;
            _loc_3.mapId = this._myData.mapId;
            if (this._myData.mapId == 0)
            {
                _loc_3.mapId = Game.mapInfo.mapId;
            }
            _loc_3.name = this._txtName.text;
            if (_loc_3.mapId != this._myData.mapId)
            {
                return _loc_3;
            }
            if (_loc_3.name != this._myData.name)
            {
                return _loc_3;
            }
            if (_loc_3.point.x != this._myData.x)
            {
                return _loc_3;
            }
            if (_loc_3.point.y != this._myData.y)
            {
                return _loc_3;
            }
            return null;
        }// end function

        override public function set data(param1:Object) : void
        {
            if (this._txtX == null)
            {
                this.createDisposedChildrenImpl();
            }
            this._myData = param1 as SmallMapCustomXYData;
            if (this._myData.isNotSet)
            {
                this._txtName.defaultText = this._myData.name;
            }
            else
            {
                this._txtName.text = this._myData.name;
            }
            this._txtMapName.text = this._myData.mapName;
            this._txtX.text = this._myData.x.toString();
            this._txtY.text = this._myData.y.toString();
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._line = UIFactory.bg(-8, 0, 392, 2, this, ImagesConst.SplitLine);
            this._txtName = UIFactory.gTextInput(0, 6, 116, 22, this);
            this._txtName.maxChars = 8;
            this._txtMapName = UIFactory.gTextInput(124, 6, 84, 22, this);
            this._txtMapName.mouseEnabled = false;
            this._lX = UIFactory.label("X", 214, 7, 30, 24, TextFormatAlign.LEFT, this);
            this._txtX = UIFactory.gTextInput(227, 6, 58, 22, this);
            this._lY = UIFactory.label("Y", 292, 7, 30, 24, TextFormatAlign.LEFT, this);
            this._txtY = UIFactory.gTextInput(304, 6, 58, 22, this);
            this._btnCur = UIFactory.gLoadedButton(ImagesConst.MapBtnPlaceXY_upSkin, 367, 5, 26, 26, this);
            this.setEnabled(this._txtX, false);
            this.setEnabled(this._txtY, false);
            this.setEnabled(this._txtMapName, false);
            this._btnCur.configEventListener(MouseEvent.CLICK, this.curPointHandler);
            return;
        }// end function

        private function setEnabled(param1:GTextInput, param2:Boolean) : void
        {
            param1.mouseEnabled = param2;
            param1.mouseChildren = param2;
            if (param2)
            {
                param1.filters = [];
            }
            else
            {
                param1.filters = [FilterConst.colorFilter];
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._line.dispose(param1);
            this._line = null;
            this._txtName.dispose(param1);
            this._txtName = null;
            this._txtMapName.dispose(param1);
            this._txtMapName = null;
            this._lX.dispose(param1);
            this._lX = null;
            this._txtX.dispose(param1);
            this._txtX = null;
            this._lY.dispose(param1);
            this._lY = null;
            this._txtY.dispose(param1);
            this._txtY = null;
            this._btnCur.dispose(param1);
            this._btnCur = null;
            return;
        }// end function

        private function curPointHandler(event:MouseEvent) : void
        {
            this._txtX.text = RolePlayer.instance.x2d.toFixed();
            this._txtY.text = RolePlayer.instance.y2d.toFixed();
            this._txtMapName.text = GameMapConfig.instance.getMapInfo(Game.mapInfo.mapId).name;
            this._myData.mapId = Game.mapInfo.mapId;
            return;
        }// end function

    }
}
